<template>
  <div class="app-container">

    <el-table
      element-loading-text="Loading"
      :data="alarmList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <el-table-column label="发生时间" align="center" >
        <template slot-scope="scope">{{ scope.row.eventTime }}</template>
      </el-table-column>
<!--      <el-table-column label="事件描述" align="center">-->
<!--        <template slot-scope="scope">{{ scope.row.eventDesc }}</template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="事件用户" align="center">-->
<!--        <template slot-scope="scope">{{ scope.row.userId }}</template>-->
<!--      </el-table-column>-->
      <el-table-column label="事件设备" align="center">
        <template slot-scope="scope">{{ scope.row.deviceCode }}</template>
      </el-table-column>
      <el-table-column label="抓拍图片" align="center">
        <template slot-scope="scope">
<!--          {{ scope.row.outStock }}-->
          <el-image :src="byteToArray(scope.row.eventDesc)"/>
        </template>

      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>
  </div>
</template>

<script>
  import $ from "@/api/accessCtrlMot"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        // 告警列表
        alarmList: [],
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      byteToArray(path){
        let reg = new RegExp('\\\\',"g")//g,表示全部替换。
        path=path.replace(reg,"/");
        return "http://localhost:8080/tb-user/imgInfo?path="+path
      },
      fetchData() {
        this.currentPage = 1
        $.eventList({
          pageIndex: this.currentPage,
          pageSize: this.pageSize
        }).then(res => {
          this.alarmList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },


      find(pageIndex){
        $.eventList({
          pageIndex: pageIndex,
          pageSize: this.pageSize
        }).then(res => {
          this.alarmList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },
    }
  }
</script>
<style>
  .el-tooltip__popper {
    max-width: 700px
  }
</style>

